<p>Swift gives us two ways of making ranges: the <code>..&lt;</code> and <code>...</code> operators. The half-open range operator, <code>..&lt;</code>, creates ranges up to but excluding the final value, and the closed range operator, <code>...</code>, creates ranges up to and <em>including</em> the final value.</p>
<p>For example, the range <code>1..&lt;5</code> contains the numbers 1, 2, 3, and 4, whereas the range <code>1...5</code> contains the numbers 1, 2, 3, 4, and 5.</p>
<p>Ranges are helpful with <code>switch</code> blocks, because you can use them for each of your cases. For example, if someone sat an exam we could print different messages depending on their score:</p>
<pre class="code">
<p></p>
<p><span class="keyword">let</span> score <span class="operator">=</span> <span class="number">85</span></p>
<p><span class="keyword">switch</span> score <span class="punctuation">{</span></p>
<p><span class="keyword">case</span> <span class="number">0</span><span class="punctuation">.</span><span class="punctuation">.</span><span class="operator">&lt;</span><span class="number">50</span><span class="punctuation">:</span></p>
<p>  <span class="function">print</span><span class="punctuation">(</span><span class="string">"You failed badly."</span><span class="punctuation">)</span></p>
<p><span class="keyword">case</span> <span class="number">50</span><span class="punctuation">.</span><span class="punctuation">.</span><span class="operator">&lt;</span><span class="number">85</span><span class="punctuation">:</span></p>
<p>  <span class="function">print</span><span class="punctuation">(</span><span class="string">"You did OK."</span><span class="punctuation">)</span></p>
<p>default<span class="punctuation">:</span></p>
<p>  <span class="function">print</span><span class="punctuation">(</span><span class="string">"You did great!"</span><span class="punctuation">)</span></p>
<p><span class="punctuation">}</span></p>
<p></p>
</pre>

<p style="height: 0px; margin-bottom: 0px;"></p>
<p>As before, the <code>default</code> case must be there to ensure all possible values are covered.</p>
